package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.LabItemDictCritical;
import com.ysd.lis.entity.lab.LabTatBaserule;
import com.ysd.lis.mapper.lab.LabTatBaseruleMapper;
import com.ysd.lis.service.lab.LabTatBaseruleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * TAT监控基础规则 服务实现类
 * </p>
 *
 * @author cfz
 * @since 2024-10-25
 */
@Service
public class LabTatBaseruleServiceImpl extends ServiceImpl<LabTatBaseruleMapper, LabTatBaserule> implements LabTatBaseruleService {
    @Autowired
    LabTatBaseruleMapper labTatBaseruleMapper;

    @Override
    public Result findLabTatBaseruleList(LabTatBaserule labTatBaserule) {
        List<LabTatBaserule> list = findLabTatBaseruleArray(labTatBaserule);
        return Result.succ(1, "请求成功", list);
    }

    @Override
    public List<LabTatBaserule> findLabTatBaseruleArray(LabTatBaserule labTatBaserule) {
        MPJLambdaWrapper<LabTatBaserule> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.eq(LabTatBaserule::getDelFlag, 0);
        queryWrapper.eq(StringUtils.isNotBlank(labTatBaserule.getId()), LabTatBaserule::getId, labTatBaserule.getId());
        return labTatBaseruleMapper.selectList(queryWrapper);
    }

    @Override
    public Result addOrUpdateBaserule(List<LabTatBaserule> labTatBaserule) {
        boolean b = this.saveOrUpdateBatch(labTatBaserule);
        if (b) {
            return Result.succ(1, "操作成功", null);
        } else {
            return Result.fail(400, "操作失败", "");
        }
    }

    @Override
    public Result addLabTatBaserule(LabTatBaserule labTatBaserule) {
        int i = labTatBaseruleMapper.insert(labTatBaserule);
        if (i > 0) {
            return Result.succ(1, "新增成功", labTatBaserule);
        }
        return Result.fail("新增失败");
    }

    @Override
    public Result deleteLabTatBaserule(LabTatBaserule labTatBaserule) {
        labTatBaserule.setDelFlag(1);
        int i = labTatBaseruleMapper.updateById(labTatBaserule);
        if (i > 0) {
            return Result.succ(1, "删除成功", labTatBaserule);
        }
        return Result.fail("删除失败");
    }

    @Override
    public Result updateLabTatBaserule(LabTatBaserule labTatBaserule) {
        int i = labTatBaseruleMapper.updateById(labTatBaserule);
        if (i > 0) {
            return Result.succ(1, "更新成功", labTatBaserule);
        }
        return Result.fail("更新失败");
    }
}
